<?php

class Quantri_HanghoadvController extends Zend_Controller_Action
{

    public function init()
    {
        $option=array(
        		"layout" => "layout",
        		"layoutPath" => APPLICATION_PATH."/layouts/scripts/quantri"
        );
        Zend_Layout::startMvc($option);
        
        $this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
    }

    public function indexAction()
    {
    	$hanghoadv = new Quantri_Model_Hanghoadv();
    	$rsHanghoadv = $hanghoadv->GetAll();
    	
    	$this->view->rsHanghoadv = $rsHanghoadv;
    	
    }

    public function saveAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        $hanghoadv = new Quantri_Model_Hanghoadv();
        
        $Id = $this->_request->getParam("idHanghoadv", "-1");
        $Ten = $this->_request->getParam("Ten","");            
        $Idnhomhhdv = $this->_request->getParam("NhomHang","");
        $Iddonvitinh = $this->_request->getParam("DonViTinh","");
        $GiaMua = $this->_request->getParam("GiaMua","");
        $GiaBan = $this->_request->getParam("GiaBan","");
        $MaVach = $this->_request->getParam("MaVach","");
        $DuongDanAnh = $this->_request->getParam("DuongDanAnh","");
        $TrangThai = $this->_request->getParam("TrangThai","off");
      
        
        if($TrangThai=="on")
            $TrangThai = 1;
        else
            $TrangThai = 0;        
      
        
        $hanghoadv->Id = $Id;
        $hanghoadv->Ten = $Ten;        
        $hanghoadv->Idnhomhhdv = $Idnhomhhdv;
        $hanghoadv->Iddonvitinh = $Iddonvitinh;
        $hanghoadv->GiaMua = $GiaMua;
        $hanghoadv->GiaBan = $GiaBan;
        $hanghoadv->MaVach = $MaVach;
        $hanghoadv->DuongDanAnh = $DuongDanAnh;
        $hanghoadv->TrangThai = $TrangThai;      
        $hanghoadv->save();
    }

    public function xoaAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        $hanghoadv = new Quantri_Model_Hanghoadv();
        $id = $this->_request->getParam("id", "-1");
        
        $hanghoadv->Xoa($id);
    }

    public function suaAction()
    {        
        

        $donvitinh = new Quantri_Model_DonViTinh();
        $this->view->rsDonvitinh = $donvitinh->GetAll()->toArray();
        
        $nhomhhdv = new Quantri_Model_Nhomhanghoadv();
        $this->view->rsNhomhhdv = $nhomhhdv->GetAll()->toArray();
        
        $idHanghoadv = $this->_request->getParam("id","-1");
        
        $hanghoadv = new Quantri_Model_Hanghoadv();
        $hanghoadv->Id = $idHanghoadv;
        
        
        $this->view->rsHanghoadv = $hanghoadv->GetById(); 
        
        //echo json_encode($rsHanghoadv);
    }

    public function updateTrangthaiAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        $hanghoadv = new Quantri_Model_Hanghoadv();
        $Id = $this->_request->getParam("id", "-1");
        $TrangThai = $this->_request->getParam("id", "-1");
        
        if($TrangThai==-1)
            return;
        
        $TrangThai = ($TrangThai==1) ? '0' : '1';
        
        $hanghoadv->TrangThai = $TrangThai;
        $hanghoadv->UpdateTrangthai();
    }

    
    public function themAction()
    {
        $donvitinh = new Quantri_Model_DonViTinh();
        $this->view->rsDonvitinh = $donvitinh->GetAll()->toArray();
        
        $nhomhhdv = new Quantri_Model_Nhomhanghoadv();
        $this->view->rsNhomhhdv = $nhomhhdv->GetAll()->toArray();
        
    }
   
}





